package domain.entities;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: scamisay
 * Date: 12/2/12
 * Time: 1:22 AM
 * To change this template use File | Settings | File Templates.
 */
public class EquipmentSiteProtocoloCompromisoPaisDAO extends HibernateDaoSupport {
    private static final Logger log = LoggerFactory
            .getLogger(EquipmentSiteProtocoloCompromisoPais.class);

    protected void initDao() {
        // do nothing
    }

    public void save(EquipmentSiteProtocoloCompromisoPais transientInstance) {
        log.debug("saving EquipmentSiteProtocoloCompromisoPais instance");
        try {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }

    public EquipmentSiteProtocoloCompromisoPais merge(EquipmentSiteProtocoloCompromisoPais detachedInstance) {
        log.debug("merging EquipmentSiteProtocoloCompromisoPais instance");
        try {
            EquipmentSiteProtocoloCompromisoPais result = (EquipmentSiteProtocoloCompromisoPais) getHibernateTemplate()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(EquipmentSiteProtocoloCompromisoPais instance) {
        log.debug("attaching dirty EquipmentSiteProtocoloCompromisoPais instance");
        try {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void delete(EquipmentSiteProtocoloCompromisoPais persistentInstance) {
        log.debug("deleting EquipmentSiteProtocoloCompromisoPais instance");
        try {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public EquipmentSiteProtocoloCompromisoPais findById(java.lang.Integer id) {
        log.debug("getting EquipmentSiteProtocoloCompromisoPais instance with id: " + id);
        try {
            EquipmentSiteProtocoloCompromisoPais instance = (EquipmentSiteProtocoloCompromisoPais) getHibernateTemplate()
                    .get("domain.entities.EquipmentSiteProtocoloCompromisoPais", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

    public List<EquipmentSiteProtocoloCompromisoPais> findByCentroId(Integer centroid) {
        log.debug("finding all Equipmentcertification instances");
        try {
            String queryString = "from EquipmentSiteProtocoloCompromisoPais e where e.equipment.centro.id = " + centroid;
            return getHibernateTemplate().find(queryString);
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }
}
